package com.example.demo.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created with IntelliJ IDEA.
 * Description: 将自定义拦截器配置到设置文件当中
 * User: yyx
 * Date: 2023-11-03
 * Time: 11:16
 */
//@Configuration
public class Appconfig implements WebMvcConfigurer {
    //方法外依赖注入
    @Autowired
    private UserInterceptor userInterceptor;

    @Override//重写添加多个拦截器的方法
    public void addInterceptors(InterceptorRegistry registry) {
//        WebMvcConfigurer.super.addInterceptors(registry);
        //方式一:直接new
        // registry.addInterceptor(new UserInterceptor());

        //方式二:依赖注入
        registry.addInterceptor(userInterceptor)//不加分号
                .addPathPatterns("/**")//拦截所有请求
                .excludePathPatterns("/user/reg")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/editor.md/**")
                .excludePathPatterns("/img/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/login.html")
                .excludePathPatterns("/reg.html");

    }
}
